<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="/component/pear/css/pear.css" />
	<link rel="stylesheet" href="/admin/css/other/person.css" />
</head>
<body class="pear-container">
	<div class="layui-row layui-col-space10">
		<!--<div class="layui-col-md3">
			<div class="layui-card">
				<div class="layui-card-body" style="padding: 25px;">
					<div class="text-center layui-text">
						<div class="user-info-head" id="userInfoHead">
							<img src="" id="userAvatar" width="115px" height="115px" alt="">
						</div>
						<h2 style="padding-top: 20px;font-size: 20px;">就眠仪式</h2>
						<p style="padding-top: 8px;margin-top: 10px;font-size: 13.5px;">China ， 中国</p>
					</div>
				</div>
				<div style="height: 45px;border-top: 1px whitesmoke solid;text-align: center;line-height: 45px;font-size: 13.5px;">
					<span>今日事 ，今日毕</span>
				</div>
			</div>
		</div>-->
		<div class="layui-col-md7">
			<div class="layui-card">
				<div class="layui-card-header">
					基本信息
				</div>
				<div class="text-center layui-text">
					<div class="user-info-head" id="userInfoHead">
						<img src="" id="userAvatar" width="115px" height="115px" alt="">
					</div>
					<h2 style="padding-top: 20px;font-size: 20px;">${currentUser.username}</h2>
				</div>
				<div class="layui-card-body">
					<form class="layui-form" action="">
								<div class="main-container">
									<div class="layui-form-item">
										<label class="layui-form-label">账号</label>
										<div class="layui-input-block">
											<input type="text" name="username" value="${currentUser.username}" autocomplete="off" placeholder="请输入账号" class="layui-input" lay-verify="required">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">姓名</label>
										<div class="layui-input-block">
											<input type="text" value="${currentUser.realName}"  name="realName" lay-verify="required" autocomplete="off" placeholder="请输入姓名" class="layui-input">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">邮箱</label>
										<div class="layui-input-block">
											<input type="text" value="${currentUser.email}"  name="email" lay-verify="email" autocomplete="off" placeholder="请输入邮箱" class="layui-input">
										</div>
									</div>
									<%--<div class="layui-form-item">
										<label class="layui-form-label">密码</label>
										<div class="layui-input-block">
											<input type="password"  name="password" lay-verify="pass" autocomplete="off" placeholder="请输入密码" class="layui-input">
										</div>
									</div>--%>
									<div class="layui-form-item">
										<label class="layui-form-label">电话</label>
										<div class="layui-input-block">
											<input type="text" value="${currentUser.phone}"  name="phone" lay-verify="phone" autocomplete="off" placeholder="请输入电话" class="layui-input">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">性别</label>
										<div class="layui-input-block">
											<c:if test="${currentUser.sex == '1'}">
												<input type="radio" name="sex" value="0" title="男" checked>
												<input type="radio" name="sex" value="1" title="女">
											</c:if>
											<c:if test="${currentUser.sex == '0'}">
												<input type="radio" name="sex" value="0" title="男">
												<input type="radio" name="sex" value="1" title="女" checked>
											</c:if>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">&nbsp;</label>
										<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
											更新基本信息
										</button>

										<button  class="pear-btn pear-btn-primary pear-btn-sm" style="margin-left: 30px;" id="pass-edit">
											修改密码
										</button>
									</div>
								</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<script src="/component/layui/layui.js"></script>
	<script src="/component/pear/pear.js"></script>
	<script>
		layui.use(['jquery', 'element', 'layer','form','admin','common'], function () {
			var element = layui.element,
				layer = layui.layer,
				$ = layui.jquery,
				admin = layui.admin,
				common= layui.common
				form = layui.form;

			$("#userAvatar").attr("src", parent.layui.$(".layui-nav-img").attr("src"));

			window.callback = function (data) {
				layer.close(data.index);
                $("#userAvatar").attr("src", data.newAvatar);
                parent.layui.$(".layui-nav-img").attr("src", data.newAvatar);
            }

			$("#userAvatar").click(function () {
				layer.open({
					type: 2,
					title: '更换图片',
					shade: 0.1,
					area: ["900px", "500px"],
					content: '/user-avatar-view',
					btn: ['确定', '取消'],
					yes: function (index, layero) {
						window['layui-layer-iframe' + index].submitForm();
					}
				});
			});



			form.on('submit(user-save)', function(data){
				data.field.userId = '${currentUser.userId}'
				$.ajax({
					url:'/user/update-base-info',
					data:JSON.stringify(data.field),
					dataType:'json',
					contentType:'application/json',
					type:'post',
					success:function(){
						layer.msg('用户基础信息修改成功,请重新登录！', {icon: 1, time: 2000}, function () {
							window.lgoutAndRefresh();
						});
					},
					error: function (data) {
						layer.msg(data.responseJSON.detail,{icon:2,time:1000});
					}
				})
				return false;
			});

			$("#pass-edit").click(function () {
				layer.open({
					type: 2,
					title: '修改密码',
					shade: 0.1,
					area: [common.isModile()?'100%':'500px', common.isModile()?'100%':'300px'],
					content: '/pass-edit-view',
					success:function (layero,index) {
						var iframe = window['layui-layer-iframe' + index];
						//将表格列内容传递给弹框，用户数据回显
						iframe.init('${currentUser.userId}')
					}
				});
				return false;
			});

			window.lgoutAndRefresh = function () {
				$.ajax({url:"/user/logout",async:false})
				parent.location.reload();
			};
		});
	</script>
</body>
</html>
